#include <util_usb_desc.h>
#include <util_usb_desc_cdc.h>

// 设备描述符
const __attribute__((aligned(4))) usb_desc_dev_t g_cdc_acm_dev_desc = {
	.base.len = sizeof(usb_desc_dev_t), // 长度固定为结构体总长度
	.base.type = 0x01,		    // 设备描述符类型
	.usb_bcd = 0x0200,		    // USB2.0
	.dev_class.usb_class = 0x02,	    // CDC类
	.dev_class.sub_class = 0x02,	    // CDC-ACM子类
	.dev_class.proto = 0x01,	    // AT命令协议
	.max_pkt_size = 64,		    // 全速设备端点0最大包长
	.vendor_id = 0x1234,		    // 示例厂商ID
	.product_id = 0x5678,		    // 示例产品ID
	.dev_bcd = 0x0100,		    // 设备版本v1.0
	.vendor_str_idx = 0,		    // 字符串描述符索引
	.prod_str_idx = 0,		    // 字符串描述符索引
	.sn_str_idx = 0,		    // 字符串描述符索引
	.cfg_nums = 1			    // 单配置
};

// 配置描述符集合
const __attribute__((aligned(4))) usb_desc_set_cdc_t g_cdc_acm_desc_set = {
	// 配置描述符
	.cfg_desc.base.len = sizeof(usb_desc_cfg_t),
	.cfg_desc.base.type = USB_DESC_TYPE_CONFIG,
	.cfg_desc.total_len = sizeof(usb_desc_set_cdc_t),
	.cfg_desc.intf_nums = 2,
	.cfg_desc.cfg_no = 1,
	.cfg_desc.cfg_str_idx = 0,
	.cfg_desc.spt_rmt_wakeup = 0,
	.cfg_desc.is_self_power = 0,
	.cfg_desc.valid = 1,
	.cfg_desc.max_pwr = 50, // 100mA

	// 接口关联描述符
	.iad_desc.base.len = sizeof(usb_desc_iad_t),
	.iad_desc.base.type = USB_DESC_TYPE_IAD,
	.iad_desc.first_intf_no = 0,
	.iad_desc.intf_nums = 2,
	.iad_desc.iad_class.usb_class = 2, // CDC通信类
	.iad_desc.iad_class.sub_class = 2,
	.iad_desc.iad_class.proto = 1,
	.iad_desc.func_str_idx = 0,

	// 通信接口
	.comm_intf.base.len = sizeof(comm_intf),
	.comm_intf.base.type = USB_DESC_TYPE_INTERFACE,
	.comm_intf.intf_no = 0,
	.comm_intf.alt_set = 0,
	.comm_intf.ep_nums = 1,
	.comm_intf.intf_class.usb_class = 2, // CDC通信类
	.comm_intf.intf_class.sub_class = 2,
	.comm_intf.intf_class.proto = 1,
	.comm_intf.intf_idx = 0,

	// 功能描述符头
	.header_desc.base.base.len = sizeof(usb_desc_cdc_header_t),
	.header_desc.base.base.type = USB_DESC_TYPE_CDC_FUNC,
	.header_desc.base.sub_type = 0,
	.header_desc.bcd = 0x0110, // CDC版本V1.1

	// 呼叫管理功能描述符
	.call_mgt_desc.base.base.len = sizeof(usb_desc_cdc_call_mgt_t),
	.call_mgt_desc.base.base.type = USB_DESC_TYPE_CDC_FUNC,
	.call_mgt_desc.base.sub_type = 1,
	.call_mgt_desc.spt_call_mgt = 0, // 不支持呼叫管理
	.call_mgt_desc.call_mgt_intf = 0,
	.call_mgt_desc.call_mgt_intf_no = 1,

	// ACM功能描述符
	.acm_desc.base.base.len = sizeof(usb_desc_cdc_acm_t),
	.acm_desc.base.base.type = USB_DESC_TYPE_CDC_FUNC,
	.acm_desc.base.sub_type = 2,
	.acm_desc.spt_comm_feat = 0,
	.acm_desc.spt_line = 1,
	.acm_desc.spt_send_brk = 0,
	.acm_desc.spt_net_notif = 0,

	// CDC联合功能描述符
	.union_desc.base.base.len =
		sizeof(usb_desc_cdc_union_v) + sizeof(u8_s[2]),
	.union_desc.base.base.type = USB_DESC_TYPE_CDC_FUNC,
	.union_desc.base.sub_type = 6,
	.intf_no_a[0] = 0,
	.intf_no_a[1] = 1,

	// 通信端点（中断传输）
	.comm_ep.base.len = sizeof(usb_desc_ep_t),
	.comm_ep.base.type = USB_DESC_TYPE_ENDPOINT,
	.comm_ep.ep_no = 1,
	.comm_ep.dir = USB_DIR_IN,
	.comm_ep.trans_type = USB_TRANS_INT, // 中断传输
	.comm_ep.iso_type = USB_DESC_EP_ISO_NONE,
	.comm_ep.iso_usage = USB_DESC_EP_ISO_DATA,
	.comm_ep.max_pkt_size = 16,
	.comm_ep.times = 0,
	.comm_ep.interval = 16, // 16ms

	// 数据接口
	.data_intf.base.len = sizeof(comm_intf),
	.data_intf.base.type = USB_DESC_TYPE_INTERFACE,
	.data_intf.intf_no = 1,
	.data_intf.alt_set = 0,
	.data_intf.ep_nums = 2,
	.data_intf.intf_class.usb_class = 10, // CDC数据类
	.data_intf.intf_class.sub_class = 0,
	.data_intf.intf_class.proto = 0,
	.data_intf.intf_idx = 0,

	// 批量输入端点
	.bulk_in_ep.base.len = sizeof(usb_desc_ep_t),
	.bulk_in_ep.base.type = USB_DESC_TYPE_ENDPOINT,
	.bulk_in_ep.ep_no = 2,
	.bulk_in_ep.dir = 1,
	.bulk_in_ep.trans_type = USB_TRANS_BULK, // 批量传输
	.bulk_in_ep.iso_type = USB_DESC_EP_ISO_NONE,
	.bulk_in_ep.iso_usage = USB_DESC_EP_ISO_DATA,
	.bulk_in_ep.max_pkt_size = 64,
	.bulk_in_ep.times = 0,
	.bulk_in_ep.interval = 0,

	// 批量输出端点
	.bulk_out_ep.base.len = sizeof(usb_desc_ep_t),
	.bulk_out_ep.base.type = USB_DESC_TYPE_ENDPOINT,
	.bulk_out_ep.ep_no = 2,
	.bulk_out_ep.dir = 0,
	.bulk_out_ep.trans_type = USB_TRANS_BULK, // 批量传输
	.bulk_out_ep.iso_type = USB_DESC_EP_ISO_NONE,
	.bulk_out_ep.iso_usage = USB_DESC_EP_ISO_DATA,
	.bulk_out_ep.max_pkt_size = 64,
	.bulk_out_ep.times = 0,
	.bulk_out_ep.interval = 0,
};
